package first.progr.helpstaff;

import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;


public class ApplicationManager {
    
	public WebDriver driver;
	public String baseUrl;
	
	//Helpers Initialization
	private NavigationHelper navigator;
	private GroupHelper grHelp;
	private ContactHelper contHelp;
	private Properties prop;
	
	public ApplicationManager(Properties prop) {
		this.prop = prop;
		String browser = prop.getProperty("browser");
		if ("firefox".equals(browser)){
			driver = new FirefoxDriver();	
		} else if ("ie".equals(browser)){
			driver = new InternetExplorerDriver();
		} else if ("chrome".equals(browser)){
			driver = new ChromeDriver();
		} else {
			throw new Error ("Current browser " + browser + " is unsupported");
		}
		
		baseUrl = prop.getProperty("baseUrl");
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		driver.get(baseUrl);
	}
	
	public void testStop() {
		driver.quit();
	   
	}
	
	public NavigationHelper navigateTo() {
	  if (navigator == null) {
		  navigator = new NavigationHelper(this);
	  }
		return navigator;
	}
	
	public GroupHelper getGroupHelper() {
		  if (grHelp == null) {
			  grHelp = new GroupHelper(this);
		  }
			return grHelp;
		}
	
	public ContactHelper getContactHelper() {
		  if (contHelp == null) {
			  contHelp = new ContactHelper(this);
		  }
			return contHelp;
		}
}
